import { ref, reactive, computed } from "vue";
import { defineStore } from "pinia";

export const useCounterStore = defineStore(
	"counter",
	() => {
		const count = ref(0);
		const dataInfo = ref({});
		const doubleCount = computed(() => count.value * 2);
		function increment() {
			count.value++;
		}

		return { dataInfo, count, doubleCount, increment };
	},
	{
		persist: {
			// 开启数据缓存
			enabled: true,
			strategies: [
				{
					key: "userInfo", //设置存储的key
					storage: sessionStorage, //表示存储在localStorage或sessionStorage
					paths: ["count", "doubleCount", "dataInfo"], //指定要长久化的字段
				},
			],
		},
	}
);
